package com.ruoyi.web.controller;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.Advice;
import com.ruoyi.business.qo.AdviceQO;
import com.ruoyi.business.service.AdviceService;
import com.ruoyi.common.common.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @title: AdviceController
 * @copyright: copyright (c) 2021
 * @author: jiangguanjun
 * @date: 2023/10/5 11:35
 * @firstReview:
 * @lastReview:
 * @desc: 公众号留言相关
 */
@Api(value = "AdviceController", tags = "公众号留言相关 ")
@RestController
@Slf4j
@RequestMapping("/advice")
public class AdviceController {
    @Autowired
    private AdviceService adviceService;



    @CrossOrigin
    @GetMapping("/list")
    @ApiOperation(value = "公众号留言列表  页面：客服-公众号留言")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "createStartTime", value = "注册开始时间", dataType = "String"),
            @ApiImplicitParam(name = "createEndTime", value = "注册结束时间", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "0：待处理 1：有效信息 2：无效信息 3：电话信息", dataType = "Integer"),
    })
    public ResultBody<IPage<Advice>> list(
                                            @RequestParam(value = "createStartTime" ,required = false) String createStartTime,
                                            @RequestParam(value = "createEndTime" ,required = false) String createEndTime,
                                            @RequestParam(value = "status" ,required = false) Integer status){


        AdviceQO adviceQO = new AdviceQO() ;
        adviceQO.setStatus(status);
        log.info("adviceQO:::::::{}",adviceQO);
        if(createEndTime != null){
            adviceQO.setCreateEndDate(createEndTime + " 23:59:59");
        }
        if(createStartTime != null){
            adviceQO.setCreateStartDate(createStartTime+" 00:00:00");
        }
        return adviceService.queryByPage(adviceQO) ;
    }


    @CrossOrigin
    @PostMapping("/deal")
    @ApiOperation(value = "处理公众号留言  页面：客服-公众号留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deal", value = "是否已经处理 0：未处理，1：已处理", dataType = "Integer"),
            @ApiImplicitParam(name = "id", value = "id", dataType = "Integer")
    })
    public ResultBody deal(@RequestBody JSONObject jsonObject){


        Integer deal = jsonObject.getInteger("status") ;
        Integer id = jsonObject.getInteger("id") ;

        Integer res = adviceService.deal(deal,id) ;
        return ResultBody.success(res>0) ;
    }


}

